import { defHttp } from '@/utils/http/axios';
import {
  RoleListGetResultModel,
  RoleParams,
  RolePageParams,
  RolePageListGetResultModel,
} from '@/api/system/model/roleModel';

const basePath = '/system/sysRole/';
const buildUrl = (url: string) => basePath + url;
enum Api {
  GetAllRoleList = 'queryAllRoleList',
  RolePageList = 'pageQuery',
  RoleAddOrUpdate = 'addOrUpdate',
  GetRoleMap = 'roleMap',
  RoleDel = 'del',
}

export const getAllRoleList = (params?: RoleParams) =>
  defHttp.get<RoleListGetResultModel>({ url: buildUrl(Api.GetAllRoleList), params });

export const getRoleMap = () => defHttp.get({ url: buildUrl(Api.GetRoleMap) });

export const getRoleListByPage = (params: RolePageParams) =>
  defHttp.post<RolePageListGetResultModel>({
    url: buildUrl(Api.RolePageList),
    params: { page: params.page, pageSize: params.pageSize, t: params },
  });

export const setRoleStatus = (id: string, status: string) =>
  defHttp.post({ url: buildUrl(Api.RoleAddOrUpdate), params: { roleId: id, status: status } });

export const roleAddOrUpdate = (params: any) =>
  defHttp.post({ url: buildUrl(Api.RoleAddOrUpdate), params });

export const roleDel = (id: string) => defHttp.get({ url: buildUrl(Api.RoleDel) + '/' + id });
